package datetime

import (
	"context"
	"fmt"
	"github.com/6tail/lunar-go/calendar"
	"github.com/beherochuling/beesoft_api/app/helper/net"
	thisModel "github.com/beherochuling/beesoft_api/app/model/util/date"
	"time"
)

var Datetime datetime

type datetime struct{}

func (r *datetime) Now(ctx context.Context, req *thisModel.NowReq) (*thisModel.NowRes, *net.Exception) {
	res := new(thisModel.NowRes)

	solar := calendar.NewSolarFromDate(time.Now().Local())
	lunar := solar.GetLunar() // lunar := calendar.NewLunarFromSolar(solar)
	foto := lunar.GetFoto()   // foto := calendar.NewTaoFromLunar(lunar)
	tao := lunar.GetTao()     // tao := calendar.NewTaoFromLunar(lunar)

	res.Other.Julian = solar.GetJulianDay()

	res.Solar.Year = solar.GetYear()
	res.Solar.Month = solar.GetMonth()
	res.Solar.Day = solar.GetDay()
	res.Solar.Hour = solar.GetHour()
	res.Solar.Minute = solar.GetMinute()
	res.Solar.Second = solar.GetSecond()
	res.Solar.Week = solar.GetWeek()
	res.Solar.IsLeapYear = solar.IsLeapYear()
	res.Solar.Short = solar.String()
	res.Solar.Full = solar.ToFullString()
	for e := solar.GetFestivals().Front(); e != nil; e = e.Next() {
		res.Solar.Festivals = append(res.Solar.Festivals, e.Value.(string))
	}
	for e := solar.GetOtherFestivals().Front(); e != nil; e = e.Next() {
		res.Solar.FestivalsOther = append(res.Solar.FestivalsOther, e.Value.(string))
	}
	res.Solar.WeekChinese = solar.GetWeekInChinese()
	res.Solar.SalaryRate = solar.GetSalaryRate()
	res.Solar.XingZuo = solar.GetXingZuo()

	res.Lunar.Short = lunar.String()
	res.Lunar.Full = lunar.ToFullString()
	for e := lunar.GetFestivals().Front(); e != nil; e = e.Next() {
		res.Lunar.Festivals = append(res.Lunar.Festivals, e.Value.(string))
	}
	for e := lunar.GetOtherFestivals().Front(); e != nil; e = e.Next() {
		res.Lunar.FestivalsOther = append(res.Lunar.FestivalsOther, e.Value.(string))
	}
	res.Lunar.Year = lunar.GetYear()
	res.Lunar.Month = lunar.GetMonth()
	res.Lunar.Day = lunar.GetDay()

	res.GanZhi.Year.GanZhi = lunar.GetYearInGanZhi()
	res.GanZhi.Year.Gan = lunar.GetYearGan()
	res.GanZhi.Year.Zhi = lunar.GetYearZhi()
	res.GanZhi.Year.GanIndex = lunar.GetYearGanIndex()
	res.GanZhi.Year.ZhiIndex = lunar.GetYearZhiIndex()
	res.GanZhi.Month.GanZhi = lunar.GetMonthInGanZhi()
	res.GanZhi.Month.Gan = lunar.GetMonthGan()
	res.GanZhi.Month.Zhi = lunar.GetMonthZhi()
	res.GanZhi.Month.GanIndex = lunar.GetMonthGanIndex()
	res.GanZhi.Month.ZhiIndex = lunar.GetMonthZhiIndex()
	res.GanZhi.Day.GanZhi = lunar.GetDayInGanZhi()
	res.GanZhi.Day.Gan = lunar.GetDayGan()
	res.GanZhi.Day.Zhi = lunar.GetDayZhi()
	res.GanZhi.Day.GanIndex = lunar.GetDayGanIndex()
	res.GanZhi.Day.ZhiIndex = lunar.GetDayZhiIndex()
	res.GanZhi.Time.GanZhi = lunar.GetTimeInGanZhi()
	res.GanZhi.Time.Gan = lunar.GetTimeGan()
	res.GanZhi.Time.Zhi = lunar.GetTimeZhi()
	res.GanZhi.Time.GanIndex = lunar.GetTimeGanIndex()
	res.GanZhi.Time.ZhiIndex = lunar.GetTimeZhiIndex()

	res.Lunar.Animal = lunar.GetAnimal()
	res.Lunar.BaZi = lunar.GetBaZi()
	res.Lunar.Chong = lunar.GetChong()
	res.Lunar.YueXiang = lunar.GetYueXiang()

	res.Lunar.ZhiXing = lunar.GetZhiXing()
	//res.Lunar.Time = lunar.GetTime()

	for e := foto.GetFestivals().Front(); e != nil; e = e.Next() {
		res.Foto.Festivals = append(res.Foto.Festivals, e.Value.(*calendar.FotoFestival).String())
	}
	for e := tao.GetFestivals().Front(); e != nil; e = e.Next() {
		res.Tao.Festivals = append(res.Tao.Festivals, e.Value.(string))
	}

	return res, nil
}
func (r *datetime) Date() {
	//solar := calendar.NewSolar(r.Solar.Year, r.Solar.Month, r.Solar.Day, r.Solar.Hour, r.Solar.Minute, r.Solar.Second)
	//solar.GetFestivals()
	//solar.GetJulianDay()
	//solar.ToFullString()
	//solar.ToYmdHms()
	lunar := calendar.NewLunarFromYmd(1986, 4, 21)
	fmt.Println(lunar.ToFullString())
	fmt.Println(lunar.GetSolar().ToFullString())
}

//	func Solarlunar(ctx context.Context, req *DateReq) *DateReq {
//		if req.Solar != "" && req.Lunar == "" {
//			req.Lunar, req.leapMonthFlag = solarlunar.SolarToLuanr(req.Solar)
//		} else if req.Lunar != "" && req.Solar == "" {
//			req.Solar = solarlunar.LunarToSolar(req.Lunar, req.leapMonthFlag)
//		}
//
//		req.LunarChinese = solarlunar.SolarToChineseLuanr(req.Solar)
//		req.LunarSimple = solarlunar.SolarToSimpleLuanr(req.Solar)
//		req.Festivals = festival.NewFestival("").GetFestivals(req.Solar)
//
//		return req
//	}
